#include <iostream>
using namespace std;


int main()
{
	string s;
	string s2;
	int n;
	int q;
	int t;
	cin >> n;
	cin >> s;
	while(n--)
	{
		cin >> q;
		if(q == 1)
		{
		   cin >> s2;
		   s+=s2;
		   cout << s << endl;	
		}
		else if (q==2)
		{
			int m,n;
			cin >> m >> n;
			s = s.substr(m,n);
			cout << s << endl;
		}
		else if (q == 3)
		{
			cin >> t >> s2;
			s.insert(t,s2);
			cout << s << endl;
		}
		else
		{
			cin >> s2;
			int ret = s.find(s2);
			if(ret == string::npos)
			cout << "-1" << endl;
			else
			cout << ret << endl;
		}
    }
	
	
	return 0;
}
